/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package my.algorithms.mcorrea;

/**
 *
 * @author mcorrea
 */
public class CountSwapsCodeSprint2011 {
	
	
	public static void main(String args[]){
	
		int[] a = {2, 1, 3, 1, 2};
		
		int count = 0; 
		for(int i=1; i<a.length; i++){
			int j = i;
			int tmp = a[i];
			while(j > 0 && tmp<a[j-1]){
				a[j] =  a[j-1]; 
				j--;
				count++;
			}
			a[j] = tmp;
		}
	
	
		for(int x: a){
			System.out.print(x+" ");
		}
		
		System.out.println("\n"+count);
	
	
	}
	
}
